package com.tedu.ds.dict.controller;

import com.tedu.ds.dict.pojo.dto.DictParam;
import com.tedu.ds.dict.pojo.dto.DictQuery;
import com.tedu.ds.dict.service.DictService;
import com.tedu.ds.base.response.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/v1/dict")
@Api(tags = "字典模块")
public class DictController {
    @Autowired
    private DictService dictService;

    @PostMapping("/select")
    @ApiOperation("查询功能")
    public JsonResult select(@RequestBody DictQuery dictQuery){
        return JsonResult.ok(dictService.select(dictQuery));
    }

    @PostMapping("/save")
    @ApiOperation("新增和更新功能")
    public JsonResult save(@RequestBody @Validated DictParam dictParam){
        dictService.save(dictParam);
        return JsonResult.ok();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除功能")
    public JsonResult deleteById(@PathVariable Integer id){
        dictService.deleteById(id);
        return JsonResult.ok();
    }
}
